package org.mdrtwell.swing.jlist;

import java.awt.BorderLayout;

import javax.swing.AbstractListModel;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class JListTest extends JPanel {
	public JListTest() {
		JList list = new JList(new AbstractListModel() {
			String[]	strs	= new String[] { "a", "gdaf", "what" };

			@Override
			public int getSize() {
				return strs.length;
			}

			@Override
			public Object getElementAt(int index) {
				return strs[index];
			}
		});
		setLayout(new BorderLayout());
		add(list, BorderLayout.CENTER);
	}

	public static void main(String[] args) {
		// 2012-5-22
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				JDialog dialog = new JDialog();
				dialog.setContentPane(new JListTest());
				dialog.pack();
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
	}
}
